package cn.icanci.ladybird.controller;

import cn.icanci.ladybird.common.result.JsonData;
import cn.icanci.ladybird.pojo.dto.UserClassDetailsDto;
import cn.icanci.ladybird.service.TicketDetailsService;
import cn.icanci.ladybird.service.user.UserClassService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;

/**
 * @author: wirdeo
 * @date: Created in 2020/10/6 14:38
 * @classAction: 处理搜索请求
 */
@SuppressWarnings("all")
@Controller
@RequestMapping("/api/v1/pub/user")
public class UserSearchController {
    @Autowired
    private UserClassService userClassService;
    @Autowired
    private TicketDetailsService ticketDetailsService;

    @ResponseBody
    @RequestMapping("/search")
    public JsonData getUserSearch(String search,Integer pageNum,Integer pageSize){
        PageInfo<UserClassDetailsDto> userClassDetailsDtoPageInfo = ticketDetailsService.queryAllBySearch(search, pageNum, pageSize);
        return JsonData.builderSuccess(userClassDetailsDtoPageInfo);
    }

    @RequestMapping("/json/search")
    public String getUserSearchJson(Model model,String search,Integer pageNum,Integer pageSize){
        PageInfo<UserClassDetailsDto> userClassDetailsDtoPageInfo = ticketDetailsService.queryAllBySearch(search, pageNum, pageSize);
        ArrayList<Object> list = new ArrayList<>();
        list.add(userClassDetailsDtoPageInfo);
        JsonData jsonData = JsonData.builderSuccess(list);
        model.addAttribute("jsonData",jsonData);
        return "user/search";
    }
}
